<!-- 通用头部组件 -->
<template>
  <div class="headerEvent">
    <div class="addev-menu">活动信息</div>
    <el-form :model="groupForm" :rules="groupFormRules" ref="groupFormRef" label-width="100px" class="demo-ruleForm">
      <!-- 团购标题 -->
      <el-form-item label="团购标题: " prop="GroupBuyTitle">
        <el-input v-model="groupForm.GroupBuyTitle" placeholder="请输入团购标题" style="width:50%"></el-input>
      </el-form-item>
      <!-- 时间 -->
      <el-form-item label="活动时间">
        <el-col :span="6">
          <el-date-picker type="datetime" placeholder="选择日期" v-model="groupForm.GroupBuyStartTime"
            value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;">
          </el-date-picker>
        </el-col>
        <el-col class="line" :span="1" style="text-align:center;">至</el-col>
        <el-col :span="6">
          <el-date-picker type="datetime" placeholder="选择日期" v-model="groupForm.GroupBuyEndTime"
            value-format="yyyy-MM-dd HH:mm:ss" style="width:100%;">
          </el-date-picker>
        </el-col>
        <el-col :span="3">
          <el-checkbox v-model="groupForm.type" label="长期" style="margin-left:30px"></el-checkbox>
        </el-col>
      </el-form-item>
      <!-- 推荐返现 -->
      <el-form-item label="推荐返现" prop="region">
        <el-select v-model="groupForm.region" placeholder="请选择推荐返现金额">
          <el-option v-for="item in regionOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="团购详情设置:">
        <el-button @click="AddText">添加文字</el-button>
        <el-button @click="AddBImg">添加大图</el-button>
        <el-button @click="AddSImg">添加小图</el-button>
        <el-button @click="AddVideo">添加视频</el-button>
      </el-form-item>
      <el-row>
        <el-form-item v-for="(item,i) in addtext" :key="i" prop="textarea" class="box">
          <el-card :body-style="{ padding: '0px' }">
            <div class="box-f">
              <div class="box-f-t">
                <p>团购文字</p>
                <el-button type="primary" icon="el-icon-delete" class="mr" @click="del1(i)">删除</el-button>
              </div>
              <div>
                <el-input v-model="groupForm.GroupBuyContentCode[0].content" type="textarea" :rows="3" placeholder="请输入文字信息"></el-input>
              </div>
            </div>
          </el-card>
        </el-form-item>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { nextTick } from 'vuedraggable'
export default {
  props: {
    parentForm: Object
  },
  data () {
    return {
      //表单的数据
      groupForm: {
        //团购标题
        GroupBuyTitle: this.parentForm.GroupBuyTitle,
        //开始时间
        GroupBuyStartTime: this.parentForm.GroupBuyStartTime,
        //结束时间
        GroupBuyEndTime: this.parentForm.GroupBuyEndTime,
        //是否长期
        type: this.parentForm.type,
        //推荐返现金额
        region: this.parentForm.region,
        GroupBuyContentCode:[
          {
            type:'text',
            content:''
          }
        ]
      },
      //表单验证规则
      groupFormRules: {
        GroupBuyTitle: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 5, message: "活动名称长度不得少于 5 个字符", trigger: "blur" }
        ]
      },
      //推荐返现金额的配置
      regionOptions: [
        { value: 1, label: "1元" },
        { value: 2, label: "2元" },
        { value: 3, label: "3元" },
      ],
      //文本,大图,小图,视频
      addtext: [],
      textflag: true
    }
  },
  //生命周期 - 创建完成（访问当前this实例）
  created () {

  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted () {

  },
  methods: {
    AddText () {
      if (this.textflag) {
        this.addtext.push(1)
        this.textflag = false
      }
    },
    AddBImg () {

    },
    AddSImg () {

    },
    AddVideo () {

    },
    //删除
    del1 (index) {
      this.addtext.splice(index,1)
      this.textflag = true;
    }
  }
}
</script>
<style lang='less' scoped>
/* @import url(); 引入css类 */
.addev-menu {
  width: 98%;
  background-color: #f8f8f8;
  margin: 0 auto;
  height: 50px;
  line-height: 50px;
  font-weight: bold;
  padding-left: 20px;
  box-sizing: border-box;
}
.el-form {
  padding-left: 100px;
}
.el-form-item {
  margin-top: 20px;
}
</style>